package stream;

import java.util.*;
import java.util.function.BiFunction;
import java.util.stream.Collectors;

/**
 * @author： pang-yun
 * @date： 2021-10-26 17:16
 * 功能目的 ：用于
 */

public class FilterStream {
    public static void main(String[] args) {
        Dog a = new Dog("a", 1);
        BiFunction<String,Integer,Dog> biFunction =Dog::new;
        Dog b = biFunction.apply("b", 2);
        Dog c = biFunction.apply("c", 3);
        Dog d = biFunction.apply("d", 4);
        Dog e = biFunction.apply("e", 5);
        Dog h = biFunction.apply("e", 5);


        ArrayList<Dog> dogs = new ArrayList<>();
        dogs.add(a);
        dogs.add(b);
        dogs.add(c);
        dogs.add(d);
        dogs.add(e);
        dogs.add(h);

        System.out.println(dogs.stream().map(Dog::getName).collect(Collectors.joining("|||")));

        Map<Integer, List<Dog>> collect = dogs.stream().collect(Collectors.groupingBy(Dog::getAge));
      /*  for (Map.Entry<Integer,List<Dog>> m: collect.entrySet()){
            System.out.println(m.getKey()+"   "+m.getValue());
        }*/
     /*   collect.forEach((k,v)->{
            System.out.println(k+"  "+v);
        });
*/

/*
        System.out.println(dogs.stream().collect(Collectors.counting()));

        System.out.println(dogs.stream().findFirst());

        System.out.println(dogs.stream().map(Dog::getAge).reduce(Integer::sum));
        System.out.println(dogs.stream().collect(Collectors.averagingInt(Dog::getAge)));*/


   /*     dogs.stream().filter(x->x.getAge()>4).forEach(System.out::println);
        System.out.println("-----------");
        Dog optional = dogs.stream().max(Comparator.comparing(Dog::getAge)).orElse(new Dog("optional", 6));
        System.out.println(optional);
        System.out.println("------");
        dogs.stream().distinct().filter(x->x.getAge()>4).forEach(System.out::println);
        System.out.println("-------");
        dogs.stream().skip(5).forEach(System.out::println);
        dogs.stream().map(Dog::getName).forEach(System.out::println);
        dogs.stream().sorted(Comparator.comparing(Dog::getAge).reversed()).distinct().forEach(System.out::println);*/
    }
}
